Arena.ResizeImmediate(565, 130)
timer = 0
tableaux = 0

require "Dialogs"

Encounter["GameMusic"] = "None"
NewAudio.Stop("One")
NewAudio.Stop("Loop")

Black = CreateSprite("Bullets/Bones/Body","Top")
Black.Scale(640/5, 480)
Black.color = {0, 0, 0}
Black.MoveTo(320, 240)
Heart = CreateSprite("Overworld/Objects/Soul","Top")
Heart.color = Player.sprite.color
Heart.MoveTo(Encounter["X"], Encounter["Y"])
Encounter["X"] = nil
Encounter["Y"] = nil

Shards = {}

function Update()
	DialogUpdate()
	timer = timer + 1
	if timer == 75 then
		Heart.Set("Overworld/Objects/Soul Dead")
		Audio.PlaySound("lol You died")
	elseif timer == 150 then
		for i=1,6 do
			table.insert(Shards, {Sprite = CreateSprite("Soul Shards/1","Top"), X = math.random(-40, 40), Y = math.random(40)})
			Shards[i].Sprite.SetAnimation({"Soul Shards/1","Soul Shards/2","Soul Shards/3","Soul Shards/4"}, 1/6)
			Shards[i].Sprite.color = Heart.color
			Shards[i].Sprite.MoveTo(Heart.x, Heart.y)
		end
		Heart.Remove()
		Heart = nil
		Audio.PlaySound("Dead")
	elseif timer == 225 then
		NewAudio.PlaySound("Loop", "Game Over", true, 1)
		GameOver = CreateSprite("Game Over","Top")
		GameOver.MoveTo(320, 360)
		GameOver.alpha = 0
	elseif timer >= 226 and timer < 301 then
		GameOver.alpha = (timer - 225)/75
	elseif timer == 350 then
		if GetAlMightyGlobal("Idioma") == "Spanish" then
			Dialog("[noskip][voice:papyrus][SetSpace:3]Oh no[w:10], estas\rbien humano?", {X = 150, Y = 140}, "papyrus", nil, 1)
		else
			Dialog("[noskip][voice:papyrus][SetSpace:3]Oh no[w:10], are you\rokay human?", {X = 150, Y = 140}, "papyrus", nil, 1)
		end
		dialogo = 1
	end
	if dialogo and Dialogues[1] and not Dialogues[1].Activo then
		if dialogo == 1 then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Dialog("[noskip][voice:papyrus][SetSpace:3]DESPIERTA![w:10] POR\rFAVOR DESPIERTA!", {X = 150, Y = 140}, "papyrus", nil, 1)
			else
				Dialog("[noskip][voice:papyrus][SetSpace:3]WAKE UP![w:10] PLEASE\rWAKE UP!", {X = 150, Y = 140}, "papyrus", nil, 1)
			end
			dialogo = 2
		elseif dialogo == 2 then
			dialogo = 3
		elseif dialogo == 3 and Input.Confirm == 1 then
			dialogo = 4
		elseif dialogo == 4 then
			if GameOver.alpha > 0 then
				GameOver.alpha = GameOver.alpha - 0.01
				if Encounter["GameMusic"] ~= "Fade" then
					Encounter["Volumen"] = 1
					Encounter["GameMusic"] = "Fade"
				end
			else
				GameOver.Remove()
				GameOver = nil
				dialogo = 5
			end
		elseif dialogo >= 5 and dialogo < 125 then
			dialogo = dialogo + 1
		elseif dialogo == 125 then
			if string.sub(GetAlMightyGlobal("Archivimentazo"), 26, 26) == "0" then
				SetAlMightyGlobal("Archivimentazo", string.sub(GetAlMightyGlobal("Archivimentazo"), 1, 25).."1")
				LogroDesbloqueado = {Timer = 0, Icon = 26}
			end
			Black.Remove()
			Black = nil
			Encounter["SkipBoxDialog"] = true
			EndWave()
		end
	end
	for i=1,#Shards do
		local Datos = Shards[i - tableaux]
		Datos.Sprite.MoveTo(Datos.Sprite.x + Datos.X/10, Datos.Sprite.y + Datos.Y/10)
		Datos.Y = Datos.Y - 1
		if Datos.Sprite.y <= -10 then
			Datos.Sprite.Remove()
			Datos = nil
			table.remove(Shards, i - tableaux)
			tableaux = tableaux + 1
		end
	end
	tableaux = 0
end